import { formatTimeToStr } from "@/utils/date";
import { getDict } from "@/utils/dictionary";

export const formatBoolean = (bool) => {
  if (bool !== null) {
    return bool ? "是" : "否";
  } else {
    return "";
  }
};
export const formatDate = (time) => {
  if (time !== null && time !== "") {
    var date = new Date(time);
    return formatTimeToStr(date, "yyyy-MM-dd hh:mm:ss");
  } else {
    return "";
  }
};

export const filterDict = (value, options) => {
  const rowLabel = options && options.filter((item) => item.value === value);
  return rowLabel && rowLabel[0] && rowLabel[0].label;
};

export const getDictFunc = async (type) => {
  const dicts = await getDict(type);
  return dicts;
};


export const IdeUIIconDict = (value) => {
  const res = { name: "", icon: "" };
  switch (value) {
    case "idea":
      res.name = "IntelliJ IDEA";
      res.icon = "../../../assets/tools-webide-idea.png";
      break;
    case "goland":
      res.name = "GoLand";
      res.icon = "../../../assets/tools-webide-goland.png";
      break;
    case "pycharm":
      res.name = "PyCharm";
      res.icon = "../../../assets/tools-webide-pycharm.png";
      break;
    case "phpstorm":
      res.name = "PhpStorm";
      res.icon = "../../../assets/tools-webide-phpstorm.png";
      break;
    case "rubymine":
      res.name = "RubyMine";
      res.icon = "../../../assets/logo-small.png";
      break;
    case "webstorm":
      res.name = "WebStorm";
      res.icon = "../../../assets/tools-webide-webstorm.png";
      break;
    default:
      res.name = "";
      res.icon = "../../../assets/logo-small.png";
      break;
  }
  return res;
};